﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MSHTML = mshtml;
using Helpers;
using Helpers.Conditions;
using Common.Constants;

namespace HtmlParsing.Helpers.Conditions
{
    public class FormCondition : BaseTagCondition<MSHTML.IHTMLFormElement>
    {
        public HttpMethod? Method { get; set; }
        public string Action { get; set; }

        public override bool IsAccepted(MSHTML.IHTMLFormElement form)
        {
            bool result = base.IsAccepted(form);

            result &= Method == null 
                || form.method.ToUpper() == Method.Value.ToString().ToUpper();
            
            result &= StringHelper.IsnullOrBlank(Action) || form.action == Action;

            return result;
        }
    }
}
